<?php

/**
 * 前台 新闻 模块 Controller
 * ============================================================================
 * TBlog TBlog博客系统　BY Tmac PHP MVC framework
 * $Author: zwt007 $  <zwttmac@qq.com>
 * $Id: anli.php 39 2011-07-11 17:12:35Z zwt007 $
 * http://www.t-mac.org；
 */
class anliAction extends Action
{

    private $tmp_model;
    private $show_model;
    private $article_model;
    private $anli_model;
    private $index_model;

    public function _init()
    {
        $this->assign('action', $_GET['TMAC_ACTION']);
        $this->tmp_model = Tmac::model('news');
        $this->show_model = Tmac::model('show');
        $this->article_model = Tmac::model('article', 'admin');
        $this->anli_model = Tmac::model('anli');
        $this->index_model = Tmac::model('index');
        $this->admincase_model = Tmac::model('casemodel', 'admin');

        $this->M('index')->getCommon();
    }

    public function index()
    {
        $name = $this->H($this->getParam('name'));
        $name = empty($name) ? 'anli' : $name;
        $catinfo = $this->show_model->getCategoryInfo($name);
        $cid = intval($this->getParam('cid'));
        $id = intval($this->getParam('id'));
        if (empty($id)) {
            $anli_list = $this->anli_model->getAnliList();
            $id = $anli_list[0]['article_id'];
        }

        $cat_list = $this->tmp_model->getCategoryList($catinfo['cat_id']);
        if (is_array($cat_list)) {
            foreach ($cat_list AS $k => $v) {
                //取文章信息
                $cat_list[$k]['info'] = $this->tmp_model->getArticleList('', $v['cat_id']);
            }
        }

        //增加一次点击数
        $this->show_model->saveArticleClick($id);
        //取文章内的图片数组和文章详情字段
        $info = $this->anli_model->getAnliInfo($id);
        $img = $this->admincase_model->getCfgBody('img', $info['imgurls']);
        $imgurl_array = $img[2];
        $imgtitle_array = $img[1];

        $nicename = $this->index_model->getToptypeNmae($name);
        $this->assign('nicename', $nicename);
        $this->assign('catinfo', $catinfo);
        $this->assign('imgurl_array', $imgurl_array);
        $this->assign('imgtitle_array', $imgtitle_array);
        $this->assign('name', $name);
        $this->assign('cat_list', $cat_list);
        $this->assign('info', $info);
        $this->V('anli');
    }

}